package com.bwie.controller;

import com.bwie.common.domain.ChargingStation;
import com.bwie.common.domain.Collect;
import com.bwie.common.domain.Vehicle;
import com.bwie.common.domain.request.ChargingRequest;
import com.bwie.common.result.PageResult;
import com.bwie.common.result.Result;
import com.bwie.mapper.VehicleMapper;
import com.bwie.service.ChargingService;
import com.bwie.service.VehicleService;
import org.apache.ibatis.annotations.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author：ShenJiaFeng
 * @Package：com.bwie.controller
 * @Project：zg6_yuekao
 * @name：ChargingController
 * @Date：2024/5/17 12:34
 */
@RestController
@RequestMapping("/charging")
public class ChargingController {
    @Autowired
    private ChargingService chargingService;
    @Autowired
    private VehicleMapper vehicleMapper;
    @Autowired
    private VehicleService vehicleService;
    @PostMapping("/list")
    public PageResult<ChargingStation> chargingList(@RequestBody ChargingRequest chargingRequest) {
        return chargingService.chargingList(chargingRequest);
    }
    //修改字典值更新
    @PostMapping("/updateType")
    public Result updateType(@RequestBody ChargingStation chargingStation){
        chargingService.updateType(chargingStation);
        return Result.success(chargingStation,"修改字典值成功");
    }
    //图片上传
    @PostMapping("/fastUpload")
    public Result fastUpload(@RequestParam("file")MultipartFile multipartFile){
        return chargingService.fastUpload(multipartFile);
    }

   //收藏接口
    @PostMapping("/addCollect")
    public Result addCollect(@RequestParam  Long chargingId){
        chargingService.addCollect(chargingId);
        return Result.success(chargingId,"收藏成功");
    }


    @PostMapping("/updStatus")
    public Result updStatus(@RequestParam  Long chargingId){
        chargingService.updStatus(chargingId);
        return Result.success(chargingId,"收藏成功");
    }

    @PostMapping("/updateStatusTwo")
    public Result updateStatusTwo(@RequestParam Long chargingId){
        chargingService.updStatusTwo(chargingId);
        return Result.success(chargingId,"取消收藏");
    }

    @PostMapping("/addVehicle")
    public Result addVehicle(@RequestBody Vehicle vehicle){
        chargingService.addVehicle(vehicle);
        return Result.success();
    }

    //设置车辆默认
    @PostMapping("/updateVehicleStatus")
    public Result updateVehicleStatus(@RequestBody Vehicle vehicle){
        chargingService.updateVehicleStatus(vehicle);
        return Result.success();
    }

    //取消默认车辆
    @PostMapping("/updateVehicleStatusTwo")
    public Result updateVehicleStatusTwo(@RequestBody Vehicle vehicle){
        chargingService.updateVehicleStatusTwo(vehicle);
        return Result.success();
    }

    @PostMapping("/selectVehicleList")
    public Result vehicleList(){
        return Result.success(
                vehicleService.list()
        );

    }

    @PostMapping("listTest")
    public List<ChargingStation> listTest(){
        List<ChargingStation> list = chargingService.list();
        return list;
    }
}
